/*绑定回车到查询按钮11*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$("#yppc-chaxun").trigger('click'); 
		return false;
		}
	});
});
$("input:text").attr('autocomplete','off');
//查询按钮
$("#yppc-chaxun").click(function(){
	dwpanduan = false;
	pageNumber = 1;
	getZsYaopinfpyeByPage($('#ypjl-mingcheng').val(),$('#yp-leibie').val());
});
var dwid = null;
var dwpanduan;
var pageNumber;
function getYaopinfpcs(preid,prepageNo,premingcheng,preleibie){
	if(prepageNo!=null&&prepageNo!='null'){
		dwid = preid;
		dwpanduan = true;
		pageNumber = prepageNo;
		$('#ypjl-mingcheng').val(premingcheng);
		$('#yp-leibie').val(preleibie);
		var leixing;
		if(preleibie==1){
			leixing="饮片";
    	}else if(preleibie==2){
    		leixing="中成药";
    	}else if(preleibie==3){
    		leixing="化学制药";
    	}else if(preleibie==4){
    		leixing="生物制药";
    	}else if(preleibie==0){
    		leixing="全部";
    	}else{
    		leixing="其他";
    	}
		$('#f-le-fenlei').text(leixing);
		getZsYaopinfpyeByPage(premingcheng,preleibie);
	}else {
		dwpanduan = false;
		pageNumber = 1;
		getZsYaopinfpyeByPage('',0);
	}
}
//查询条件重置按钮
$("#yppc-reset").click(function(){
	dwpanduan = false;
	pageNumber = 1;
	$('#ypjl-mingcheng').val('');
	$('#yp-leibie').val(0);
	$('#f-le-fenlei').text('全部');
	getZsYaopinfpyeByPage($('#ypjl-mingcheng').val(),$('#yp-leibie').val());
});

//点击类型下拉菜单
$("#leixing li").click(function(){
	var bText = $(this).text();
	var bValue = $(this).val();
	$(this).parent().parent().find(".dropdown-toggle").text(bText);
	$(this).parent().parent().find("#yp-leibie").val(bValue);
	$(this).parent().css("display","none");
	dwpanduan = false;
	pageNumber = 1;
	getZsYaopinfpyeByPage($('#ypjl-mingcheng').val(),bValue);
});


// 获取分页数据
function getZsYaopinfpyeByPage(mingcheng,leixing) {
	var totalNumber = 0;
    $.ajax({
        //请求方式为get
        type:"POST",
        //获取json文件路径
        url:path+"/kucunpc/getZsYaopinfpyeCount",
        //传送数据
        data:{mingcheng:mingcheng,leixing:leixing},
        async:false,
        //请求成功完成后要执行的方法
        success: function(data){
        	totalNumber = data;
	    	if(totalNumber==0){
				$("#a-table-list").css("display","none");
				$("#yp-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
			}else{
				$("#a-table-list").css("display","block");
				$("#yp-img").html("");
			}
        }
    });
    
	$('#kucunyppc').html('');
	var container = $('#pagination-fenyyp');
	container.pagination({
		dataSource:path+'/kucunpc/getZsYaopinfpyeByPage?mingcheng='+mingcheng+'&leixing='+leixing,
		locator: '',
		pageSize: 12,
		totalNumber: totalNumber,
		pageNumber:pageNumber,
		showNavigator: true,
	    formatNavigator: '共 <%= totalNumber %> 条',
		callback: function(data, pagination){
			var content = '';
			$(data).each(function(index,value){
				var index=((pagination.pageNumber-1)*pagination.pageSize)+index+1;
				var leixing = this.leixing;
				if(leixing==1){
					leixing="饮片";
	        	}else if(leixing==2){
	        		leixing="中成药";
	        	}else if(leixing==3){
	        		leixing="化学制药";
	        	}else if(leixing==4){
	        		leixing="生物制药";
	        	}else {
	        		leixing="其他";
	        	}
				var mingcheng;
				if(this.bieming != null && this.bieming !='') {
					mingcheng = this.bieming;
				} else {
					mingcheng = this.mingcheng;
				}
				var gongyingshang = this.gongyingshang || '';
				content += '<tr id="yppchang'+this.id+'">'+
						   '<td width="5%">'+index+'</td>'+
						   '<td width="13%">'+this.pici+'</td>'+
						   '<td class="left"  width="13%">'+mingcheng+'</td>'+
						   '<td width="10%">'+leixing+'</td>'+
						   '<td width="11%">'+this.baozhuanggg+'</td> '+
						   '<td class="left" width="12%">'+gongyingshang+'</td> '+
						   '<td width="10%">'+this.jinhuojia.toFixed(8)+'</td>'+
						   '<td width="10%">'+this.xiaoshoujia.toFixed(8)+'</td>'+
						   '<td width="8%">'+this.rukusl+this.rukudw+'</td> '+
						   '<td width="8%"><span style="color:#00b472;" id='+this.id+' onclick="toYaopinfpcxw('+this.id+','+pagination.pageNumber+',\''+$('#ypjl-mingcheng').val()+'\','+$('#yp-leibie').val()+')">编辑</span></td> ';
			});
			$('#kucunyppc').html(content);
			if(dwpanduan){
				$('#kucunyppc').find('tr[id="yppchang'+dwid+'"]').addClass('list-tr');
			} else {
				$('#kucunyppc').find('tr[id="yppchang'+dwid+'"]').removeClass('list-tr');
			}
		}
	});
    
	if(totalNumber <= 12) {
		$('#pagination-fenyyp').css('display','none');
	}else{
		$('#pagination-fenyyp').css('display','block');
	}
}
// 编辑页面跳转
function toYaopinfpcxw(id,prepageNo,premingcheng,preleibie){
	var dwmingcheng=encodeURI(encodeURI(premingcheng));
	$("#cedan").load(path+"/views/kucun/kucun-pici/bianjiyp-kc.jsp?ID="+id+"&dwpageNo="+prepageNo+"&dwmingcheng="+dwmingcheng+"&dwleibie="+preleibie);
}